package com.aidong.device.controllers;

import com.aidong.device.controllers.concerns.Success;
import com.aidong.device.entity.ExLog;
import com.aidong.device.service.ExCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * Created by aidong on 2017/2/21.
 */
@RequestMapping("/courses/")
@RestController
public class ExCourseController {
	@Autowired
	ExCodeService exCodeService;

	@RequestMapping(value = "{code}", method = RequestMethod.GET)
	public Success course(@PathVariable("code") String code, @RequestParam("machineId") String machineId,
						  @RequestParam("lessonType") int lessonType) {
		return exCodeService.getAppointment(machineId, code, lessonType);
	}

	@RequestMapping(value = "{code}", method = RequestMethod.POST)
	public Success notify(@PathVariable("code") String code, @RequestParam("machineId") String machineId,
						  @RequestParam("lessonType") int lessonType) {
		ExLog exLog = new ExLog(code, machineId, lessonType, 1, 1);
		exCodeService.addExLog(exLog, machineId);
		return new Success(new ModelMap());
	}
}